import mongoengine as db

from app.db import BaseDocument, BaseEmbeddedDocument


class Mark(BaseEmbeddedDocument):
    id = db.StringField(default='mark')
    label = db.StringField(default='已读')


class Action(BaseEmbeddedDocument):
    mark = db.EmbeddedDocumentField(Mark, default=Mark)


class Notifications(BaseDocument):
    meta = {
        'collection': 'notifications',
    }

    category = db.StringField(default='告警通知', choices=['告警通知', '服务公告'])  # 消息类别
    from_ = db.StringField(default='系统')  # 消息来源, e.g 张三 / 系统 / 副中心
    to = db.ListField(default=[])  # 消息接收用户 ID
    level = db.StringField(default='info', choices=['success', 'error', 'warning', 'info'])  # 消息内容级别
    isMarked = db.BooleanField(default=False)  # 标记状态
    action = db.EmbeddedDocumentField(Action, default=Action)  # 操作 { "用户ID": "操作类型" }
    title = db.StringField(default='')  # 标题
    message = db.StringField(default='')  # 消息正文
    data = db.DictField(default={})  # 附加信息
    choosedActionMap = db.DictField(default={})  # 操作对应的 ID,  { [uid]: String }
    isMarkedMap = db.DictField(default={})  # 标记状态. { [uid]: Boolean }
    datetime = db.DateTimeField()  # 发送日期
